/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */

package com.fuyao.cloud.asset.purchaseorderlist.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.asset.entity.AssetPurchaseorderList;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.asset.purchaseorderlist.service.AssetPurchaseorderListService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 采购订单清单
 *
 * @author liyue
 * @date 2021-11-24 10:55:39
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fyassetpurchaseorderlist" )
@Api(value = "fyassetpurchaseorderlist", tags = "采购订单清单管理")
public class AssetPurchaseorderListController {

    private final AssetPurchaseorderListService fyAssetPurchaseorderListService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param fyAssetPurchaseorderList 采购订单清单
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_view')" )
    public R getFyAssetPurchaseorderListPage(Page page, AssetPurchaseorderList fyAssetPurchaseorderList) {
        return R.ok(fyAssetPurchaseorderListService.page(page, Wrappers.query(fyAssetPurchaseorderList)));
    }


    /**
     * 通过id查询采购订单清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(fyAssetPurchaseorderListService.getById(id));
    }

    /**
     * 新增采购订单清单
     * @param fyAssetPurchaseorderList 采购订单清单
     * @return R
     */
    @ApiOperation(value = "新增采购订单清单", notes = "新增采购订单清单")
    @SysLog("新增采购订单清单" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_add')" )
    public R save(@RequestBody AssetPurchaseorderList fyAssetPurchaseorderList) {
        return R.ok(fyAssetPurchaseorderListService.save(fyAssetPurchaseorderList));
    }

    /**
     * 修改采购订单清单
     * @param fyAssetPurchaseorderList 采购订单清单
     * @return R
     */
    @ApiOperation(value = "修改采购订单清单", notes = "修改采购订单清单")
    @SysLog("修改采购订单清单" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_edit')" )
    public R updateById(@RequestBody AssetPurchaseorderList fyAssetPurchaseorderList) {
        return R.ok(fyAssetPurchaseorderListService.updateById(fyAssetPurchaseorderList));
    }

    /**
     * 通过id删除采购订单清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除采购订单清单", notes = "通过id删除采购订单清单")
    @SysLog("通过id删除采购订单清单" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(fyAssetPurchaseorderListService.removeById(id));
    }

    @ApiOperation(value = "通过ids删除采购订单清单", notes = "通过ids删除采购订单清单")
    @SysLog("通过ids删除采购订单清单" )
    @GetMapping("/delPurchaseOrderList" )
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_del')" )
    public R removeByIds(@RequestParam("ids") Long [] ids) {
        return R.ok(fyAssetPurchaseorderListService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 导出excel 表格
     * @param fyAssetPurchaseorderList 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_export')" )
    public List<AssetPurchaseorderList> export(AssetPurchaseorderList fyAssetPurchaseorderList) {
        return fyAssetPurchaseorderListService.list(Wrappers.query(fyAssetPurchaseorderList));
    }

	@ApiOperation(value = "通过parentId加载采购列表信息", notes = "通过parentId加载采购列表信息")
	@GetMapping("/getPurchaseOrderList/{parentId}" )
	@PreAuthorize("@pms.hasPermission('purchaseorder_fyassetpurchaseorder_view')" )
	public R getPurchaseOrderList(@PathVariable("parentId") Long parentId) {
		return R.ok(this.fyAssetPurchaseorderListService.list(Wrappers.<AssetPurchaseorderList>lambdaQuery().eq(AssetPurchaseorderList::getParentId, parentId)));
	}
}
